1   /*
2    * Copyright (C) 2011 The Guava Authors
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package com.google.common.util.concurrent;
18  
19  import java.util.concurrent.ExecutionException;
20  import java.util.concurrent.Future;
21  
22  import javax.annotation.Nullable;
23  
24  /**
25   * A callback for accepting the results of a {@link java.util.concurrent.Future}
26   * computation asynchronously.
27   *
28   * <p>To attach to a {@link ListenableFuture} use {@link Futures#addCallback}.
29   *
30   * @author Anthony Zana
31   * @since 10.0
32   */
33  public interface FutureCallback<V> {
34    /**
35     * Invoked with the result of the {@code Future} computation when it is
36     * successful.
37     */
38    void onSuccess(@Nullable V result);
39  
40    /**
41     * Invoked when a {@code Future} computation fails or is canceled.
42     *
43     * <p>If the future's {@link Future#get() get} method throws an {@link
44     * ExecutionException}, then the cause is passed to this method. Any other
45     * thrown object is passed unaltered.
46     */
47    void onFailure(Throwable t);
48  }